{__NOLAYOUT__}
<!DOCTYPE html>
<html id="scroll1">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<title></title>
	{include file="public/script" /}
</head>
<body>
	<div class="sectionH sectionH2  mui-clearfix">
		<header class="mui-bar mui-bar-nav" style="">
			<a class="mui-icon mui-icon-left-nav  mui-pull-left" href="javascript:history.back(-1)" style="color: #727272;"></a>
			<h1 class="mui-title">私聊记录</h1>
		</header>
	</div>
	<div class="kong1"></div>
	<div class="section2" style="position: absolute;z-index: 2;width: 100%;height: 93%;">
		<div class="container" style="position: absolute;width: 100%;z-index: 1;">
			<div class="section2-1 mui-clearfix" style="position: relative;">
				{volist name="chat_list" id="v"}
				<div {if condition="$getuserid == $v['send_uid']"}class="mai-{$v['ty']}  mui-clearfix"{else/}class="shang-{$v['ty']}  mui-clearfix" {/if}>
					<div class="logo">

						<img src="{$v.head_img|default='/static/default_avatar.png'}"/>

					</div>
					<div {if condition="$getuserid == $v['send_uid']"}class="shijian leftx"{else /}class="shijian lefty"{/if}>
						<span>{$v.ctime}</span>
					</div>

					<div class="center">
						<span>{$v.content}</span>
					</div>
					<input type='hidden' value="{$v.id}" />
				</div>
				{/volist}
			</div>
		</div>
	</div>

</body>
<script>
    mui.init({
        pullRefresh: {
            container: '.section2',
            down: {

            },
            up: {
                auto:false,
                contentrefresh: '正在加载...',
                callback: pullupRefresh
            }
        }

    });
    var getid = "{$getuserid}";
    var count = 1;
    var finish = false;
    function pullupRefresh() {
        setTimeout(function() {
            ++count;

            $.ajax({
                type: "POST",
                url: "{:url('Chat/history')}",
                data: {page:count,getid:getid},
                dataType: "json",
                success: function(data){
                    if(data.result_code==='0000'){
                        var list = data.result_data.list;
                        if(list.length===0){
                            finish=true;
                        }
                        mui('.section2').pullRefresh().endPullupToRefresh((finish)); //参数为true代表没有更多数据了。
                        var table = document.body.querySelector('.section2-1');
                        if(list.length>0){
                            for(var i=0;i<list.length;i++){
								var headimg = list[i]['head_img'];
								if(headimg==''){
								    headimg = '/static/default_avatar.png';
								}
                                var div = document.createElement('div');
                                if(getid == list[i]['send_uid']){

                                    var classname = 'shijian leftx';
                                    div.className = 'mai-'+list[i].ty+'  mui-clearfix';
                                }else{

                                    var classname = 'shijian lefty';
                                    div.className = 'shang-'+list[i].ty+'  mui-clearfix';
                                }

                                var html = 	'<div class="logo">'+
                                    '<img src="'+headimg+'"/>'+
                                    '</div>'+
                                    '<div class="'+classname+'">'+
                                    '<span>'+list[i].ctime+'</span>'+
                                    '</div>'+
                                    '<div class="center">'+
                                    '<span>'+list[i].content+'</span>'+
                                    '</div>'+
                                    '<input type="hidden" value="'+list[i].id+'" />';

                                div.innerHTML = html;
                                table.appendChild(div);
                            }
                        }
                    }else if(data.result_code==='1111'){
                        mui.alert('请登录','',function(){
                            window.location.href='/Login/login';
                        });
                    }else{
                        mui.alert(data.result_info);
                    }

                }
            });
        }, 500);
    }
</script>
<script type="text/javascript">

$(function (){

    var getid = "{$getuserid}";

    //拉取信息
    function loadmessage(){

        var lastid = $(".section2-1").find("input:last").val();
        if(lastid==undefined){
            return false;
        }

        var img_dui = "{$chat_maninfo.avatar|default='/static/default_avatar.png'}";
		var img_wo = "{$uinfo.avatar|default='/static/default_avatar.png'}";
        $.ajax({
            type:'post',
            url:"{:url('Chat/loadMessage')}",
            data:{lastid:lastid,getid:getid},
            cache:false,
            dataType:'JSON',
            success:function(data){
                if(data.result_code==='0000'){
                    var list = data.result_data.list;
                    var table = document.body.querySelector('.section2-1');
                    if(list.id>0){

                        $('html, body, .prolist').animate({scrollTop: $(document).height()}, 1);
                    }
                }else if(data.result_code==='1111'){
                    mui.alert('请登录','',function(){
                        window.location.href='/Login/login';
                    });
                }else{
                    mui.toast(data.result_info);
                }

            }
        });
	}

});
</script>
</html>